<script type="text/javascript">
$('#cep').live('blur', function(){
	url = "/address/get-address?cep="+$(this).val(),
	
	$.get(url, function(data){
		address = data;
			if(data != null){
				$('#address').val(address.address_type+" "+address.address);

				$('#neigh').val(address.neighborhood);

				$('#state').val(address.state);

				$('#city').val(address.city);
				
			}else{
				$('#address').val("");
				
				$('#neigh').val("");

				$('#state').val("");

				$('#city').val("");
			}
		}, 'json')
})
</script>

<?php if($this->errorMessages != null) :?>
	<div class="alert">
		<img src="../css/images/caution.png" class="left padding">
		<b class="left">Por favor, verifique os campos em vermelho.</b>
	</div>
<?php endif;?>

<form id="newUser" action="/user/create-user" method="POST">

	<h2>
		<span><img src="../css/images/user.png" width="40"> </span>Meu Cadastro
	</h2>

	<div class="form-div">
		<div class="form-cont">
			<h5>Os campos com * são de preenchimento obrigatório e essenciais
				para o envio dos pedidos.</h5>

			<div
				class="req <?php if(isset($this->errorMessages['login'])) echo "error"?>">
				<div class="reqi">
					<input id="login" name="login" size="30" maxlength="15"
						value="<?php echo $this->form['login']?>"> <label><?php if(isset($this->errorMessages['login'])) echo $this->errorMessages['login']?>
					</label>
				</div>
				<div class="reql">
					<label>*Apelido </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['name'])) echo "error"?>">
				<div class="reqi">
					<input id="name" name="name" size="60" maxlength="60"
						value="<?php echo $this->form['name']?>"> <label><?php if(isset($this->errorMessages['name'])) echo $this->errorMessages['name']?>
					</label>
				</div>
				<div class="reql">
					<label>*Nome Completo </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['birth'])) echo "error"?>">
				<div class="reqi">
					<input id="birth" name="birth" size="20" maxlength="10" onfocus="maskDate(this)"
						value="<?php echo $this->form['birth']?>"> <label><?php if(isset($this->errorMessages['birth'])) echo $this->errorMessages['birth']?>
					</label>
				</div>
				<div class="reql">
					<label>*Data de Nascimento </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['gender'])) echo "error"?>">
				<div class="reqi">
					<select id="gender" name="gender">
						<option selected="selected" value="">Selecione</option>
						<option
						<?php if($this->form['gender'] == "1") echo 'selected="selected"'?>
							value="1">Masculino</option>
						<option
						<?php if($this->form['gender'] == "2") echo 'selected="selected"'?>
							value="2">Feminino</option>
					</select> <label><?php if(isset($this->errorMessages['gender'])) echo $this->errorMessages['gender']?>
					</label>
				</div>
				<div class="reql">
					<label>*Sexo </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['cpf'])) echo "error"?>">
				<div class="reqi">
					<input id="cpf" name="cpf" size="35" maxlength="14" onfocus="maskCpf(this)"
						value="<?php echo $this->form['cpf']?>"> <label><?php if(isset($this->errorMessages['cpf'])) echo $this->errorMessages['cpf']?>
					</label>
				</div>
				<div class="reql">
					<label>*CPF </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['phone'])) echo "error"?>">
				<div class="reqi">
					<input id="phone" name="phone" size="20" maxlength="14" onfocus="maskPhone(this)"
						value="<?php echo $this->form['phone']?>"> <label><?php if(isset($this->errorMessages['phone'])) echo $this->errorMessages['phone']?>
					</label>
				</div>
				<div class="reql">
					<label>*Telefone Principal </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['celphone'])) echo "error"?>">
				<div class="reqi">
					<input id="celphone" name="celphone" size="20" maxlength="14" onfocus="maskPhone(this)"
						value="<?php echo $this->form['celphone']?>"> <label><?php if(isset($this->errorMessages['phone'])) echo $this->errorMessages['celphone']?>
					</label>
				</div>
				<div class="reql">
					<label>Telefone Celular </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['email'])) echo "error"?>">
				<div class="reqi">
					<input id="email" name="email" size="45" maxlength="60" 
						value="<?php echo $this->form['email']?>"> <label><?php if(isset($this->errorMessages['email'])) echo $this->errorMessages['email']?>
					</label>
				</div>
				<div class="reql">
					<label>*E-mail </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['password'])) echo "error"?>">
				<div class="reqi">
					<input type="password" id="pass" name="pass" size="30"
						maxlength="10"> <label><?php if(isset($this->errorMessages['password'])) echo $this->errorMessages['password']?>
					</label>
				</div>
				<div class="reql">
					<label>*Senha </label>
				</div>
			</div>
			<div class="clear"></div>

			<div
				class="req <?php if(isset($this->errorMessages['confirm'])) echo "error"?>">
				<div class="reqi">
					<input type="password" id="passcon" name="passcon" size="30"
						maxlength="10"> <label><?php if(isset($this->errorMessages['confirm'])) echo $this->errorMessages['confirm']?>
					</label>
				</div>
				<div class="reql">
					<label>*Confirma Senha </label>
				</div>
			</div>
			<div class="clear"></div>
			
			<div class="req">
				<div class="reqi">
					<input type="checkbox" checked="checked" id="flagmail" name="flagmail" value="1"> <label>Desejo receber e-mails com novidades.</label>
				</div>
			</div>
			<div class="clear"></div>
		</div>
	</div>

	<div class="clear"></div>

	<h2>
		<span><img src="../css/images/house.png" width="40"> </span>Meu Endereço
	</h2>

	<div class="form-div">
		<div class="form-cont">
			<h5>Os campos com * são de preenchimento obrigatório e essenciais
				para o envio dos pedidos.</h5>
			<div class="req <?php if(isset($this->errorMessages['cep'])) echo "error"?>">
				<div class="reqi">
					<input id="cep" name="cep" size="15" maxlength="9" value="<?php echo $this->addForm['cep']?>" onfocus="maskCep(this)">
					<label><?php if(isset($this->errorMessages['cep'])) echo $this->errorMessages['cep']?>	</label>
				</div>
				<div class="reql">
					<label>*CEP </label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['type'])) echo "error"?>">
				<div class="reqi">
					<input <?php if($this->addForm['type'] == 1) echo 'checked="checked"';?> type="radio" name="type" value="1"> Casa 
					<input <?php if($this->addForm['type'] == 2) echo 'checked="checked"';?> type="radio" name="type" value="2"> Apartamento 
					<input <?php if($this->addForm['type'] == 3) echo 'checked="checked"';?> type="radio" name="type" value="3"> Comercial
					<label><?php if(isset($this->errorMessages['type'])) echo $this->errorMessages['type']?>	</label>
				</div>
				<div class="reql">
					<label>*Tipo do Endereço </label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['address'])) echo "error"?>">
				<div class="reqi">
					<input id="address" name="address" size="60" maxlength="60" value="<?php echo $this->addForm['address']?>">
					<label><?php if(isset($this->errorMessages['address'])) echo $this->errorMessages['address']?>	</label>
				</div>
				<div class="reql">
					<label>*Endereço </label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['number'])) echo "error"?>">
				<div class="reqi">
					<input id="number" name="number" size="10" maxlength="5" value="<?php echo $this->addForm['number']?>">
					<label><?php if(isset($this->errorMessages['number'])) echo $this->errorMessages['number']?>	</label>
				</div>
				<div class="reql">
					<label>*Número </label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['comp'])) echo "error"?>">
				<div class="reqi">
					<input id="comp" name="comp" size="20" maxlength="20" value="<?php echo $this->addForm['comp']?>">
					<label><?php if(isset($this->errorMessages['comp'])) echo $this->errorMessages['comp']?>	</label>
				</div>
				<div class="reql">
					<label>Complemento </label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['neigh'])) echo "error"?>">
				<div class="reqi">
					<input id="neigh" name="neigh" size="45" maxlength="45" value="<?php echo $this->addForm['neigh']?>">
					<label><?php if(isset($this->errorMessages['neigh'])) echo $this->errorMessages['neigh']?>	</label>
				</div>
				<div class="reql">
					<label>*Bairro</label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['city'])) echo "error"?>">
				<div class="reqi">
					<input id="city" name="city" size="30" maxlength="30" value="<?php echo $this->addForm['city']?>">
					<label><?php if(isset($this->errorMessages['city'])) echo $this->errorMessages['city']?>	</label>
				</div>
				<div class="reql">
					<label>*Cidade </label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['state'])) echo "error"?>">
				<div class="reqi">
					<input id="state" name="state" size="30" maxlength="2" value="<?php echo $this->addForm['state']?>">
					<label><?php if(isset($this->errorMessages['state'])) echo $this->errorMessages['state']?>	</label>
				</div>
				<div class="reql">
					<label>*Estado</label>
				</div>
			</div>
			<div class="clear"></div>

			<div class="req <?php if(isset($this->errorMessages['reference'])) echo "error"?>">
				<div class="reqi">
					<textarea rows="5" cols="35" name="reference" id="reference"><?php echo $this->addForm['reference']?></textarea>
					<label><?php if(isset($this->errorMessages['reference'])) echo $this->errorMessages['reference']?>	</label>
				</div>
				<div class="reql">
					<label>Informações</label>
				</div>
			</div>
			<div class="clear"></div>
		</div>
	</div>

	<div class="right">
		<input class="button" type="submit" value="Cadastrar">
	</div>
</form>
